package xin.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.entity.CommonResult;
import xin.service.TAuthRolePermissionService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/permissionRole")
public class RolePermissionController {
    @Resource
    private TAuthRolePermissionService rolePermissionService;

    /**
     * 为角色授权
     * @param roleId
     * @param list
     * @return
     */
    @PostMapping("/add/{roleId}")
    public CommonResult<?> addPermission(@PathVariable("roleId") Long roleId, @RequestBody List<String> list){
       return this.rolePermissionService.addPermission(roleId,list)>0?CommonResult.success(null,"授权成功"):CommonResult.error(499,"授权失败");
    }

    /**
     * 查找角色所拥有的权限信息
     * @param roleId
     * @return
     */
    @GetMapping("/findRoleHasPermission")
    public CommonResult<?> findRoleHasPermission(Long roleId){
        return CommonResult.success(this.rolePermissionService.findUserHasPermission(roleId),"请求成功");
    }
}
